<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 父类
        function People(name, age, sex) {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }
        People.prototype.sayHello = function() {
            console.log('你好，我是' + this.name + '我今年' + this.age + '岁了');
        }
        People.prototype.sleep = function() {
                console.log(this.name + '开始睡觉');
            }
            // 子类拥有父类全部的属性和方法
        function Student(name, age, sex, school, studentNumber) {
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.school = school
            this.studentNumber = studentNumber
        }
        // 关键语句实现继承
        Student.prototype = new People();
        Student.prototype.study = function() {
            console.log(this.name + '正在学习');
        }
        Student.prototype.exam = function() {
            console.log(this.name + '正在测试， 加油！');
        }
        var hanmeimei = new Student('韩梅梅', 9, '女', '慕课小学', 100556);
        console.log(hanmeimei.sleep());
        // 重写，复写（override）父类的sayHello
        Student.prototype.sayHello = function() {
            console.log('敬礼！我是' + this.name + '我今年' + this.age + '岁了');
        }
    </script>
</body>

</html>